// charger.js - 充电桩信息存储模块

const state = {
  pileId: uni.getStorageSync('pileId') || '',
  socketSn: uni.getStorageSync('socketSn') || ''
}

const mutations = {
  SET_PILE_ID(state, pileId) {
    state.pileId = pileId
    uni.setStorageSync('pileId', pileId)
  },
  CLEAR_PILE_ID(state) {
    state.pileId = ''
    uni.removeStorageSync('pileId')
  },
  SET_SOCKET_SN(state, socketSn) {
    state.socketSn = socketSn
    uni.setStorageSync('socketSn', socketSn)
  },
  CLEAR_SOCKET_SN(state) {
    state.socketSn = ''
    uni.removeStorageSync('socketSn')
  }
}

const actions = {
  // 设置充电桩ID
  setPileId({ commit }, pileId) {
    commit('SET_PILE_ID', pileId)
  },
  
  // 清除充电桩ID
  clearPileId({ commit }) {
    commit('CLEAR_PILE_ID')
  },
  
  // 设置充电枪编号
  setSocketSn({ commit }, socketSn) {
    commit('SET_SOCKET_SN', socketSn)
  },
  
  // 清除充电枪编号
  clearSocketSn({ commit }) {
    commit('CLEAR_SOCKET_SN')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
} 